# -*- coding: utf-8 -*-
"""
Created on Sat Sep 14 14:00:19 2024

@author: Administrator
"""
import tkinter as tk

root =tk.Tk()
root.geometry('800x600')
root.title("canvas demo")

canvas=tk.Canvas(root,width=600,height=800,bg='white')

canvas.pack(anchor=tk.CENTER,expand=True)
#text 
canvas.create_text(
 (100, 400),
 text="Canvas Demo",
 fill="orange",
 font="tkDefaeultFont 21")


#line
canvas.create_line(0,0,100,100,width=4,fill='red')

#rectangle
canvas.create_rectangle(100,100,200,200,width=2,fill="blue")

#oval 
points=(
        (200,200),
        (300,300)
        )

canvas.create_oval(*points, fill="purple")

#polygon
def draw_polygon(moveX=0,moveY=300):
    
    x=0
    x=x+moveY
    points=(
    (0+moveX,moveY),
    (200+moveX,moveY),
    (100+moveX,50+moveY)
    )
    print(points)
    canvas.create_polygon(*points,fill="green")
    return points
    
points=draw_polygon(100,350)

#text

def draw_text(points):
   
    #*points[0] 解包元祖 ，把元祖解析为单个变量

    for x in points:
        currentPStr=str(x)
        canvas.create_text(*x, 
                              text=currentPStr,
                              fill="black",
                              font="tkDefaeultFont 12")


draw_text(points)

root.mainloop()